﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using MetarCommonSupport.SNMP;

namespace SwicthCloseTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private int SetIfPortStatus(string ip, string community, uint index, int status)
        {
            MessageBox.Show("caojun:开始设置！");
            uint[] OidIfAdminStatus = { 1, 3, 6, 1, 2, 1, 2, 2, 1, 7, 0 };
            OidIfAdminStatus[10] = index;

            if (ip != "" && community != "")
            {
                SNMP snmpObj = new SNMP(ip, community);
                if (snmpObj == null)
                {
                    MessageBox.Show("caojun:snmpObj初始化失败！");
                }
                if (snmpObj.IsVailidatePortIndex(index))
                {
                    if (status == 1 || status == 2 || status == 3)
                    {
                        snmpObj.Set(index, status);
                        System.Threading.Thread.Sleep(1000);
                        int retStatus = snmpObj.TestStatus(OidIfAdminStatus);
                        MessageBox.Show("caojun:    " + retStatus.ToString());
                        MessageBox.Show("caojun:结束设置！");
                        return retStatus;
                    }
                }
                else
                {
                    MessageBox.Show("caojun:短口不可用！");
                }
            }
            return 0;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            SetIfPortStatus(textBox1.Text.Trim(), textBox2.Text.Trim(), uint.Parse(textBox3.Text.Trim()), int.Parse(textBox4.Text.Trim()));
        }
    }
}